package com.dishdex.menuhub.module.module.category.mapper;

import com.dishdex.menuhub.module.module.category.entity.Category;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Select("select * from category where id = #{id} and is_deleted=0")
    Category getById(@Param("id") Long id);

    @Select("select * from category where id = #{id}")
    Category extractById(@Param("id") Long id);

    Long update(Category category);

    Long insert(Category category);

    @Update("update category set is_deleted=1 where id=#{id} and is_deleted=0")
    int deleteById(@Param("id") Long id);

    List<Category> getAll(@Param("categoryId") Long categoryId);

    @Select("select * from category where parent_id=#{categoryId}")
    List<Category> getMore(@Param("categoryId") Long categoryId);

    List<Long> getIds(@Param("keyword") String keyword);

    @Select("select id from category where parent_id=0")
    List<Long> getLevelOneIds();

    @Select("select id from category where parent_id between 1 and 3")
    List<Long> getLevelTwoIds();

}